<%--
  Created by IntelliJ IDEA.
  User: DELL
  Date: 2024/4/22
  Time: 16:19
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page isELIgnored="false" %>
<html>
<head>
    <title>学生选课</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css">
    <script src="/static/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
    <script src="/static/layui/layui.js" type="text/javascript" charset="utf-8"></script>
    <script src="/static/mylayer.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
    <!--顶部：搜索form表单-->
    <form class="layui-form">
        所在系：
        <div class="layui-inline layui-input-wrap">
            <select id="xiId" name="xiId" lay-filter="xiId">
                <option value="">请选择</option>
            </select>
        </div>

        <div class="layui-inline">
            <button class="layui-btn" lay-submit lay-filter="submitSearch">搜索</button>
            <button type="reset" class="layui-btn layui-btn-primary">清空</button>
        </div>
    </form>

    <!--页内容-->
    <table class="layui-hide" id="test" lay-filter="test"></table>

    <%--左上角：头部工具栏事件---批量删除、添加--%>
    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm" lay-event="add">选课</button>
        </div>
    </script>



    <script>
        /*layui库中表单模块form，表格模块table,日期选择器模块laydate*/
        layui.use(['form','table'],function (){
            var form = layui.form;
            var table = layui.table;


            $.post(
                '/xi?method=selectAll',
                function (result) {
                    if (result.code == 0){
                        $(result.data).each(function () {
                            $('#xiId').append('<option value="'+this.id+'">'+this.name+'</option>');
                        })
                        //局部变动，渲染一下
                        form.render('select');
                    }
                },
                'json'
            );

            // 创建渲染实例
            table.render({
                elem:'#test', /*页内容的id*/
                id:'tableId',
                url:'/studentCou?method=selectByPage',
                toolbar: '#toolbarDemo',
                cols:[[
                    {field:'id',title:'ID',sort:true,width: 80},/*sort用于排序*/
                    {field: 'name',title: '课程名'},
                    {field: 'gredit',title: '学分',width: 100},
                    {field: 'place',title: '上课地点'},
                    {field: 'xiName',title: '所在系'}
                ]],
                page: true
            });

            //搜索提交
            form.on('submit(submitSearch)',function (data) {
                //获得表单字段
                var field = data.field;
                //执行搜索重载
                table.reload('tableId',{
                    page: {
                        //重新从第1页开始
                        curr:1
                    },
                    //搜索的字段
                    where:field
                });
                //阻止默认 form跳转
                return false;
            });

            //头部工具栏事件---批量删除、添加
            table.on('toolbar(test)',function (obj) {
                var id = obj.config.id;
                var checkStatus = table.checkStatus(id);
                var othis = lay(this);

                switch (obj.event){
                    //----------------------添加------------------------------
                    case 'add':
                        var index = layer.open({
                            type:2,
                            title:'添加选课',
                            area:['50%','50%'],// 宽高
                            content: '/page/studentcou/add?id='+ ${user.id},
                        });
                        break;
                    case 'LAYTABLE_TIPS':
                        layer.alert('自定义工具栏图标按钮');
                        break;
                }
            });

        });
    </script>
</body>
</html>
